package com.itzyf.pokemondata.activity.rank

import android.content.Intent
import android.view.Menu
import android.view.MenuItem
import androidx.recyclerview.widget.DividerItemDecoration
import com.itzyf.pokemondata.R
import com.itzyf.pokemondata.adapter.MenuAdapter
import com.itzyf.pokemondata.bean.MainDo
import com.itzyf.pokemondata.bean.PokemonDo
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction
import com.tydic.baselibrary.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_main.*

/**
 * @author 依风听雨
 * @version 创建时间：2019/01/19 17:18
 */
class RankListActivity : BaseActivity() {
    override fun handlerActivity() {
        val mainList = listOf(
            MainDo("血量排行榜", R.drawable.ic_hp, type = PokemonDo.HP),
            MainDo("物攻排行榜", R.drawable.ic_attack, type = PokemonDo.PA),
            MainDo("物防排行榜", R.drawable.ic_defensive, type = PokemonDo.PD),
            MainDo("特攻排行榜", R.drawable.ic_sa, type = PokemonDo.SA),
            MainDo("特防排行榜", R.drawable.ic_defensive, type = PokemonDo.SD),
            MainDo("速度排行榜", R.drawable.ic_speed, type = PokemonDo.SPEED),
            MainDo("速度排行榜-修正版", R.drawable.ic_speed)
        )

        val adapter = MenuAdapter(R.layout.item_main, mainList)
        rv_list.adapter = adapter
        rv_list.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
        adapter.setOnItemClickListener { _, _, position ->
            if (mainList[position].type > 0) {
                val intent = Intent(this@RankListActivity, RankActivity::class.java)
                intent.putExtra("type", mainList[position].type)
                startActivity(intent)
            } else {
                startActivity(Intent(this@RankListActivity, RankSpeedReviseActivity::class.java))
            }
        }
    }

    override fun getContentViewId() = R.layout.activity_main

    override fun getToolbarTitle() = "各项排行榜"


    override
    fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.rank, menu)
        return true
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        item?.let {
            when (it.itemId) {
                R.id.action_help -> {
                    val builder = QMUIDialog.MessageDialogBuilder(this)
                        .setMessage("排行榜为满特训红1的数据，速度修正版为宠的极限速度（不包含限定）")
                        .setTitle("帮助")
                        .addAction(
                            "确定"
                        ) { dialog, _ ->
                            dialog.dismiss()
                        }

                    builder.show()
                }
                else -> {
                }
            }
        }
        return super.onOptionsItemSelected(item)
    }
}